package com.pic.others.controller;


import com.pic.common.utils.R;
import com.pic.others.domain.dto.picture.PictureWithCategoryDTO;
import com.pic.others.domain.po.Note;
import com.pic.others.domain.po.Picture;
import com.pic.others.domain.vo.note.NotePictureVO;
import com.pic.others.domain.vo.note.NoteWithContentVO;
import com.pic.others.service.INoteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/note")
@Slf4j
@RequiredArgsConstructor
@Api(tags = "关于笔记操作")
public class NoteController {
    private final INoteService noteService;

    @ApiOperation("删除笔记")
    @DeleteMapping("/{noteId}")
    public R<String> DeleteNote(@PathVariable @ApiParam(value = "笔记的id",example = "1")
                                            long noteId){
        return noteService.deleteByNoteId(noteId);
    }

    @ApiOperation("通过笔记id获取笔记详情")
    @GetMapping("/{noteId}")
    public R<NotePictureVO>QueryByNoteId(@PathVariable("noteId")
                                      @ApiParam(value = "笔记的id",example = "1") long noteId){
        return noteService.queryByNoteId(noteId);
    }

//     @ApiOperation("修改笔记")
//    @PutMapping("/change")
//    public R<String>updateNote(@RequestBody Note note, MultipartFile[]pictures){
//        return noteService.updateNote(note, Arrays.asList(pictures));
//     }


    @ApiOperation("修改文字")
    @PostMapping("/updateContent")
    public R<String>updateContent(@RequestBody Note note){
        return noteService.updateContent(note);
    }


     @ApiOperation("新增笔记")
    @PostMapping("/addNote")
    public R<String>addNote(@RequestBody Note note,@RequestParam("file")MultipartFile pictures){
        return noteService.addNote(note,pictures);
     }
//     public R<String> addNote(@RequestParam("file") MultipartFile pictures,
//                           @RequestParam("noteContent") String note
//                           ) {
//                 return noteService.addNote(note,pictures);
//     }

    @ApiOperation("上传文字")
    @PostMapping("/addNoteByContent")
    public R<String>addNoteByContent(@RequestBody NoteWithContentVO vo){
        return noteService.addNoteByContent(vo);
    }


    @ApiOperation("上传图片or 修改图片")
    @PostMapping("/addNoteByPicture/{noteId}")
    public R<String>addNoteByPicture(@PathVariable("noteId") Long noteId, MultipartFile file){
        log.info("file:{}",file);
        log.info("进去上传图片");
        return noteService.addNoteByPicture(noteId,file);
    }
//    //返回路径，时间，图片id,时间
//    @ApiOperation("上传单张图片")
//    @PostMapping("/fileupload")
//    public R<String> FileUpload(HttpServletRequest request, MultipartFile file) {
//        return pictureService.fileupload(file);
//    }
     @ApiOperation("检测用户可能需要的图片")
     @GetMapping()
    public R<List<Picture>>getPictureByMaybeNeed(String content){
       return noteService.getPictureByMaybeNeed(content);
     }

    @PostMapping("/getAllNoteByUserId")
    @ApiOperation("获取用户所有笔记")
    public R<List<NotePictureVO>>getAllNoteByUserId(){
        return noteService.getAllNoteByUserId();
    }

    @ApiOperation("以时间分组展示图片")
    @PostMapping("/getAllNoteByUserIdInGroup")
    public R<Map<LocalDate,List<NotePictureVO>>>getAllNoteByUserInGroup(){
        return noteService.getAllNoteByUserInGroup();
    }


}
